home *** CD-ROM | disk | FTP | other *** search
- property pFirstSprite, pLastSprite, pOpenSpot, pGameOverFrame, pSlideSound, pPieceWidth, pPieceHeight, pUpperLeftLoc, pMode, completo
-
- on getPropertyDescriptionList me
- list = [:]
- addProp(list, #pFirstSprite, [#comment: "First Sprite", #format: #integer, #default: 11])
- addProp(list, #pLastSprite, [#comment: "Last Sprite", #format: #integer, #default: 25])
- addProp(list, #pOpenSpot, [#comment: "Open Spot (point(x,y))", #format: #point, #default: point(4, 4)])
- addProp(list, #pSlideSound, [#comment: "Slide Sound", #format: #string, #default: EMPTY])
- addProp(list, #pGameOverFrame, [#comment: "Game Over Frame", #format: #marker, #default: #next])
- return list
- end
-
- on beginSprite me
- completo = 0
- pPieceWidth = sprite(pFirstSprite).width
- pPieceHeight = sprite(pFirstSprite).height
- pUpperLeftLoc = sprite(pFirstSprite).loc
- pMode = #normal
- randomizePieces(me)
- end
-
- on randomizePieces me
- posList = []
- repeat with s = pFirstSprite to pLastSprite
- add(posList, sprite(s).loc)
- end repeat
- repeat with s = pFirstSprite to pLastSprite
- r = random(posList.count)
- sprite(s).loc = posList[r]
- deleteAt(posList, r)
- end repeat
- end
-
- on clickPuzzle me, spriteNumber
- if pMode <> #normal then
- exit
- end if
- X = ((sprite(spriteNumber).locH - pUpperLeftLoc.locH) / pPieceWidth) + 1
- Y = ((sprite(spriteNumber).locV - pUpperLeftLoc.locV) / pPieceHeight) + 1
- if pOpenSpot.locV = Y then
- if pOpenSpot.locH = (X - 1) then
- move(me, spriteNumber, -1, 0)
- else
- if pOpenSpot.locH = (X + 1) then
- move(me, spriteNumber, 1, 0)
- end if
- end if
- else
- if pOpenSpot.locH = X then
- if pOpenSpot.locV = (Y - 1) then
- move(me, spriteNumber, 0, -1)
- else
- if pOpenSpot.locV = (Y + 1) then
- move(me, spriteNumber, 0, 1)
- end if
- end if
- end if
- end if
- end
-
- on move me, spriteNumber, dx, dy
- newLoc = sprite(spriteNumber).loc + point(dx * pPieceWidth, dy * pPieceHeight)
- pOpenSpot = pOpenSpot - point(dx, dy)
- sendSprite(spriteNumber, #changeLoc, newLoc)
- if pSlideSound <> EMPTY then
- puppetSound(pSlideSound)
- end if
- pMode = #animate
- end
-
- on resetMode me
- pMode = #normal
- if checkForGameOver(me) then
- member("congrats").text = "Complete!"
- end if
- end
-
- on checkForGameOver me
- prevLoc = sprite(pFirstSprite).loc
- repeat with i = pFirstSprite + 1 to pLastSprite
- nextLoc = sprite(i).loc
- if nextLoc.locH <> (prevLoc.locH + pPieceWidth) then
- if (nextLoc.locV <> (prevLoc.locV + pPieceHeight)) or (nextLoc.locH <> pUpperLeftLoc.locH) then
- return 0
- end if
- end if
- prevLoc = nextLoc
- end repeat
- completo = 1
- return 1
- end
-
- on exitFrame
- sprite(29).visible = 0
- if sprite(30).rollover = 1 then
- sprite(29).visible = 1
- else
- sprite(29).visible = 0
- end if
- if completo = 1 then
- go("Game Over")
- else
- go(the frame)
- end if
- end
-